const router = require('koa-router')()
const mysql = require('mysql');
const https = require("http");
const { query } = require('../public/javascripts/db')

router.post('/login', async (ctx, next) => {
    ctx.body = 'koa2 login'
    let { avatarUrl, nickname, openid } = ctx.request.body
    console.log(ctx.request.body)
    let sql = 'insert into user(src,user_name,user_id) value(?, ?, ?)';
    let sql1 = "select * from user where user_id = ?"
    await query(sql1, [openid]).then((results) => {
        if (results.length === 0) {
            query(sql, [avatarUrl, nickname, openid]);
        }
    })

})

module.exports = router